#!/usr/bin/python
 
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
 
GMAIL_LOGIN = 'john.graves.at.uu@gmail.com'
GMAIL_PASSWORD = 'ASDFasdf1'
 
def send_email(subject, link, from_addr=GMAIL_LOGIN, to_addr=GMAIL_LOGIN):
    msg = MIMEMultipart('alternative')
    msg['Subject'] = subject
    msg['From'] = from_addr
    msg['To'] = to_addr
    
    # Create the body of the message (a plain-text and an HTML version).
    text = "Your SlideSpeech presentation has been published here:\n{0}\n".format(link)
    html = """\
    <html>
      <head></head>
      <body>
        <p><a href="http://slidespeechweb.pagekite.me/static/{0}/odpName.htm">Link to SlideSpeech presentation</a>
        </p>
        <p><a href="http://slidespeechweb.pagekite.me/static/{0}/odpName.zip">Link to ZIP file of SlideSpeech presentation</a>
        </p>
        <p><a href="http://slidespeechweb.pagekite.me/static/{0}/odpName_NoAudio.zip">Link to ZIP file of SlideSpeech presentation (no audio for mobile)</a>
        </p>
        <p><a href="http://slidespeechweb.pagekite.me/static/{0}/output.zip">Link to JSON-ized ZIP file of SlideSpeech presentation (no audio for mobile)</a>
        </p>
      </body>
    </html>
    """.format(link)
    
    # Record the MIME types of both parts - text/plain and text/html.
    part1 = MIMEText(text, 'plain')
    part2 = MIMEText(html, 'html')
    
    # Attach parts into message container.
    # According to RFC 2046, the last part of a multipart message, in this case
    # the HTML message, is best and preferred.
    msg.attach(part1)
    msg.attach(part2)

    server = smtplib.SMTP('smtp.gmail.com',587) #port 465 or 587
    server.ehlo()
    server.starttls()
    server.ehlo()
    server.login(GMAIL_LOGIN,GMAIL_PASSWORD)
    server.sendmail(from_addr, to_addr, msg.as_string())
    server.close()
 
 
if __name__=="__main__":
    send_email('test', 'This is a test email')

